package com.bwf.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/26 10:45
 * @Copyright 博为峰
 */
public class UDPReceDemo02 {
    public static void main(String[] args) throws Exception {
        DatagramSocket ds = new DatagramSocket(9999);
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
            ds.receive(packet);
            String rece = new String(packet.getData(), 0, packet.getLength());
            System.out.println(rece);
            System.out.println(packet.getAddress().getHostName());
        }
//        ds.close();
    }
}
